package com.hundred.item.module.screen;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.hundred.item.dao.dataobject.ItemDO;
import com.hundred.item.manager.ItemManager;

public class TopItemsList {

	private static final Logger logger = LoggerFactory.getLogger(TopItemsList.class);

	@Autowired
	private ItemManager itemManager;
	
	public void execute(Context context, Navigator nav) {
		
		List<ItemDO> topList = itemManager.getTopItemList(0, 0, 5);

		for(ItemDO item:topList){
			titleProcess(item);
			logger.error("");
		}
		
		context.put("items", topList);
		
		logger.error("------------------TopItemList:"+topList.size());
		
	}

	private void titleProcess(ItemDO itemDO){
			
			if(itemDO!=null && itemDO.getItemName()!=null){
				String[] titleStrArray = itemDO.getItemName().split("。");
				String[] titleStrArray2 = itemDO.getItemName().split("，");
				if(titleStrArray.length>=1 && titleStrArray2.length>=1){
					String oneStr = titleStrArray[0];
					String twoStr = titleStrArray2[0];
					String newTitle = oneStr.length()<=twoStr.length()?oneStr:twoStr;
					itemDO.setItemName(newTitle);
				}
				else if(titleStrArray.length>=1){
					String newTitle = titleStrArray[0];
					itemDO.setItemName(newTitle);
				}
	
			}
		}
	
	public ItemManager getItemManager() {
		return itemManager;
	}

	public void setItemManager(ItemManager itemManager) {
		this.itemManager = itemManager;
	}
}
